declare @SQL varchar(max);


--terminate connections to and drop the database (if it exists)
set @SQL = 'if exists (select name from sys.databases where name = N''BIMonitor'')
  begin
    alter database BIMonitor
      set
        restricted_user with rollback immediate;
    drop database BIMonitor;
  end';
exec(@SQL);


--create the database
set @SQL = 'create database BIMonitor;'
exec(@SQL);


--set ODS database settings
set @SQL = 'alter database BIMonitor
  set
--    compatibility_level = 100,
    auto_create_statistics on,
    auto_update_statistics on,
    auto_shrink on,
    recovery simple;'
exec(@SQL);